package com.lz.repository.ly.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lz.entity.Customer;
import com.lz.repository.ly.CustomerRepository;

@Repository
public class CustomerRepositoryImpl implements CustomerRepository {

	@Autowired
	private SessionFactory sessionFactory;
	
	private Session getSession() {
		return sessionFactory.getCurrentSession();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Customer> getAll() {
		String hql = "from Customer";
		return getSession().createQuery(hql).list();
	}

	@Override
	public Customer getCustomerById(Integer id) {
		String hql = "from Customer customer where customer.customerId = :var1";
		return (Customer) getSession().createQuery(hql).setInteger("var1", id).uniqueResult();
	}

}
